package com.booksystem.controller;

import com.booksystem.common.RestResult;
import com.booksystem.dto.ApproveReviewDTO;
import com.booksystem.dto.GetReviewsDTO;
import com.booksystem.dto.SubmitReviewDTO;
import com.booksystem.entity.ProductReviewDO;
import com.booksystem.service.ProductReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   商品评价控制器
 * </p>
 * @author 段伟豪
 */
@Api("商品评价管理")
@RestController
@RequestMapping("/review")
@Slf4j
public class ProductReviewController {

    @Autowired
    private ProductReviewService productReviewService;

    /**
     * 提交商品评价
     *
     * @param submitReviewDTO 提交评价参数
     * @return RestResult结果
     */
    @PostMapping("/submit")
    @ApiOperation("提交商品评价")
    public RestResult<Boolean> submitReview(@Valid @RequestBody SubmitReviewDTO submitReviewDTO) {
        log.info("提交商品评价: {}", submitReviewDTO);
        return productReviewService.submitReview(submitReviewDTO);
    }

    /**
     * 获取商品评价列表
     *
     * @param getReviewsDTO 查询参数
     * @return RestResult结果
     */
    @GetMapping("/list")
    @ApiOperation("获取商品评价列表")
    public RestResult<List<ProductReviewDO>> getReviews(@Validated GetReviewsDTO getReviewsDTO) {
        log.info("获取商品评价列表: {}", getReviewsDTO);
        return productReviewService.getReviews(getReviewsDTO);
    }

    /**
     * 审核商品评价
     *
     * @param approveReviewDTO 审核参数
     * @return RestResult结果
     */
    @PutMapping("/approve")
    @ApiOperation("审核商品评价")
    public RestResult<Boolean> approveReview(@Valid @RequestBody ApproveReviewDTO approveReviewDTO) {
        log.info("审核商品评价: {}", approveReviewDTO);
        return productReviewService.approveReview(approveReviewDTO);
    }
}